import { useModel } from "umi";
import { useReactive } from "ahooks";

import { AllOrganizationApplicationRoles } from "../_graphql/application";

const useOrganizationApplicationRole = () => {
    const { graphqlFetchPlatform } = useModel("global");

    const state = useReactive({
        dataLoading: false,
        submitLoading: false,
        roles: [],
        totalCount: 0,
    });

    const loadOrganizationApplicationRoles = async () => {
        state.dataLoading = true;
        let res = await graphqlFetchPlatform({ query: AllOrganizationApplicationRoles, variables: {} });
        state.roles = res?.a?.nodes || [];
        state.totalCount = res?.a?.totalCount || 0;
        state.dataLoading = false;
    };

    return { ...state, loadOrganizationApplicationRoles };
};

export default useOrganizationApplicationRole;
